package com.gzbugu.bugusys.action;

import java.util.List;

import javax.annotation.Resource;

import com.gzbugu.bugusys.bean.PageModel;
import com.gzbugu.bugusys.service.ShowContractServiceService;
import com.opensymphony.xwork2.ActionSupport;

/**
 * @author Bokchoy 展示劳务合同记录
 */
public class ShowContractServiceAction extends ActionSupport {

	private static final long serialVersionUID = 1L;

	private Short contractServiceTypeId;
	private List contractServiceList;
	@Resource(name="showContractServiceService")
	private ShowContractServiceService service;
	private PageModel pageModel;
	private String staffId = "";
	private Integer year;
	private Integer month;
	
	public String execute() {
		if(pageModel==null) {
			pageModel = new PageModel();
		}
		service.setPageModel(pageModel);
		Short typeId = null;
		if (contractServiceTypeId != null) {
			typeId = new Short((short) 7);
			if (contractServiceTypeId == 1)
				typeId = (short) 7;
			else if (contractServiceTypeId == 2)
				typeId = (short) 8;
			else if (contractServiceTypeId == 3)
				typeId = (short) 9;
		}
		if(!"".equals(staffId) && year != null) {
			// first when staffId and year are provided
			this.contractServiceList = service.findContractServiceByMonthAndId(staffId,year,month,typeId);
		} else if(!staffId.equals("")) {
			// when year is not provided
			this.contractServiceList = service.findContractServiceByStaffId(staffId,typeId); 
		} else if(year != null) {
			// when staffId is not provided
			this.contractServiceList = service.findContractServiceByMonth(year,month,typeId);
		} else if(typeId!=null) {
			// when only typeId is provided
			this.contractServiceList = service.findContractServiceByTypeId(typeId);
		} else if(typeId==null) {
			// when nothing is provided
			this.contractServiceList = service.findAllContractService();
		}
		return SUCCESS;
	}
	
	public void validate() {
		
	}

	public Short getContractServiceTypeId() {
		return contractServiceTypeId;
	}

	public void setContractServiceTypeId(Short contractServiceTypeId) {
		this.contractServiceTypeId = contractServiceTypeId;
	}

	public List getContractServiceList() {
		return contractServiceList;
	}

	public void setContractServiceList(List contractServiceList) {
		this.contractServiceList = contractServiceList;
	}

	public PageModel getPageModel() {
		return pageModel;
	}

	public void setPageModel(PageModel pageModel) {
		this.pageModel = pageModel;
	}

	public String getStaffId() {
		return staffId;
	}

	public void setStaffId(String staffId) {
		this.staffId = staffId;
	}

	public Integer getYear() {
		return year;
	}

	public void setYear(Integer year) {
		this.year = year;
	}

	public Integer getMonth() {
		return month;
	}

	public void setMonth(Integer month) {
		this.month = month;
	}

}
